home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWDebug / FWDbgStr.cpp next >
Encoding:
Text File  |  1996-09-17  |  6.9 KB  |  257 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWDbgStr.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #include <stddef.h>
  13.  
  14. // Need to include first so that FW_DEBUG is properly defined
  15. #ifndef FWDBGSTR_H
  16. #include "FWDbgStr.h"
  17. #endif
  18.  
  19. #ifdef FW_DEBUG
  20.  
  21. #ifndef SLPRIDEB_H
  22. #include "SLPriDeb.h"
  23. #endif
  24.  
  25. #ifndef FWPRIMEM_H
  26. #include "FWPriMem.h"
  27. #endif
  28.  
  29. #ifndef FWPRISTR_H
  30. #include "FWPriStr.h"
  31. #endif
  32.  
  33. #ifndef FWPRIDEB_H
  34. #include "FWPriDeb.h"
  35. #endif
  36.  
  37. #if defined(FW_BUILD_MAC) && !defined(__FILES__)
  38. #include <Files.h>
  39. #endif
  40.  
  41. #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
  42. #include <Errors.h>
  43. #endif
  44.  
  45. #if defined(FW_BUILD_MAC) && !defined(__TEXTUTILS__)
  46. #include <TextUtils.h>
  47. #endif
  48.  
  49. #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
  50. #include <Script.h>
  51. #endif
  52.  
  53. #ifdef FW_BUILD_MAC
  54. #pragma segment FWDebug
  55. #endif
  56.  
  57. //========================================================================================
  58. //    CLASS FW_CDebugStream
  59. //========================================================================================
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // FW_CDebugStream::EndLine
  63. //----------------------------------------------------------------------------------------
  64.  
  65. FW_CDebugStream& EndLine(FW_CDebugStream &stream)
  66. {
  67. #ifdef FW_BUILD_MAC
  68.     char cr = 0x0D;
  69.     return stream.Write((void*)&cr, sizeof(char));
  70. #endif
  71. #ifdef FW_BUILD_WIN
  72.     char cr[2] = {0x0D, 0x0A}
  73.     return stream.Write((void*)cr, sizeof(char) * 2);
  74. #endif
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // FW_CDebugStream::FW_CDebugStream
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_CDebugStream::FW_CDebugStream()
  82. {
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. // FW_CDebugStream::~FW_CDebugStream
  87. //----------------------------------------------------------------------------------------
  88.  
  89. FW_CDebugStream::~FW_CDebugStream()
  90. {
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. // FW_CDebugStream::WriteChunk
  95. //----------------------------------------------------------------------------------------
  96.  
  97. FW_CDebugStream &FW_CDebugStream::WriteChunk(const void* data, size_t size)
  98. {
  99.     return Write(data, size);
  100. //    return Write((void*) " ", sizeof(char));
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. // FW_CDebugStream::WriteBase10Number(long n)
  105. //----------------------------------------------------------------------------------------
  106.  
  107. FW_CDebugStream & FW_CDebugStream::WriteBase10Number(unsigned long n)
  108. {
  109.     char buf[20];
  110.     char *s = &buf[20];
  111.  
  112.     *--s = 0;
  113.     do
  114.     {
  115.         *--s = (char) (n % 10) + '0';
  116.         n /= 10;
  117.     } while (n != 0);
  118.  
  119.     return WriteChunk((void*) s, FW_PrimitiveStringLength(s));
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. // FW_CDebugStream::WriteBase16Number(long n)
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_CDebugStream & FW_CDebugStream::WriteBase16Number(unsigned long n)
  127. {
  128.     const char *digits = "0123456789ABCDEF";
  129.     char buf[11] = "0x00000000";
  130.     char *s = &buf[10];
  131.     
  132.     for (; n != 0; n /= 16)
  133.         *--s = digits[(short) (n % 16)];
  134.  
  135.     return WriteChunk((void*) buf, 10);
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. // FW_CDebugStream::operator<<(const signed char *string)
  140. //----------------------------------------------------------------------------------------
  141.  
  142. FW_CDebugStream & FW_CDebugStream::operator<<(const signed char *string)
  143. {
  144.     return WriteChunk((void*) string, FW_PrimitiveStringLength((const char *) string));
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. // FW_CDebugStream::operator<<(signed char c)
  149. //----------------------------------------------------------------------------------------
  150.  
  151. FW_CDebugStream & FW_CDebugStream::operator<<(signed char c)
  152. {
  153.     return WriteChunk((void*) &c, sizeof(char));
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // FW_CDebugStream::operator<<(long n)
  158. //----------------------------------------------------------------------------------------
  159.  
  160. FW_CDebugStream & FW_CDebugStream::operator<<(long n)
  161. {
  162.     if (n < 0)
  163.     {
  164.         Write((void*) "-", sizeof(char));
  165.         n = -n;
  166.     }
  167.     return WriteBase10Number(n);
  168. }
  169.  
  170. //----------------------------------------------------------------------------------------
  171. // FW_CDebugStream::operator<<(unsigned long n)
  172. //----------------------------------------------------------------------------------------
  173.  
  174. FW_CDebugStream & FW_CDebugStream::operator<<(unsigned long n)
  175. {
  176.     return WriteBase10Number(n);
  177. }
  178.  
  179. //----------------------------------------------------------------------------------------
  180. // FW_CDebugStream::operator<<(void* p)
  181. //----------------------------------------------------------------------------------------
  182.  
  183. FW_CDebugStream & FW_CDebugStream::operator<<(void* p)
  184. {
  185.     return WriteBase16Number((long) p);
  186. }
  187.  
  188.  
  189. //========================================================================================
  190. //    CLASS FW_CMacDebugStr
  191. //========================================================================================
  192.  
  193. //----------------------------------------------------------------------------------------
  194. // FW_CMacDebugStr::FW_CMacDebugStr
  195. //----------------------------------------------------------------------------------------
  196. #ifdef FW_BUILD_MAC
  197. FW_CMacDebugStr::FW_CMacDebugStr()
  198. {
  199.     fStr255[0] = 0;
  200. }
  201. #endif
  202.  
  203. //----------------------------------------------------------------------------------------
  204. // FW_CMacDebugStr::~FW_CMacDebugStr
  205. //----------------------------------------------------------------------------------------
  206. #ifdef FW_BUILD_MAC
  207. FW_CMacDebugStr::~FW_CMacDebugStr()
  208. {
  209.     Flush();
  210. }
  211. #endif
  212.  
  213. //----------------------------------------------------------------------------------------
  214. // FW_CMacDebugStr::Write
  215. //----------------------------------------------------------------------------------------
  216. #ifdef FW_BUILD_MAC
  217. FW_CDebugStream &FW_CMacDebugStr::Write(const void* data, size_t size)
  218. {
  219.     const char *p = (const char *)data;
  220.  
  221.     while (size-- != 0)
  222.     {
  223.         char ch = *p++;
  224.  
  225.         switch (ch)
  226.         {
  227.         case 0x0D:
  228.         case '\0':
  229.             Flush();
  230.             break;
  231.  
  232.         default:
  233.             if (fStr255[0] == 255)
  234.                 Flush();
  235.             fStr255[++fStr255[0]] = ch;
  236.             break;
  237.         }
  238.     }
  239.  
  240.     return *this;
  241. }
  242. #endif
  243.  
  244. //----------------------------------------------------------------------------------------
  245. // FW_CMacDebugStr::Flush
  246. //----------------------------------------------------------------------------------------
  247. #ifdef FW_BUILD_MAC
  248. void FW_CMacDebugStr::Flush()
  249. {
  250.     if (fStr255[0] != 0)
  251.         ::DebugStr(fStr255);
  252.     fStr255[0] = 0;
  253. }
  254. #endif
  255.  
  256. #endif // FW_DEBUG
  257.